<template>
  <div>
    <el-container class="box">
      <el-aside width="200px">
        <el-menu
          default-active="/"
          class="el-menu-vertical-demo"
          text-color="#fff"
          active-text-color="#FFFF99"
          background-color="#003333"
          unique-opened
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-s-operation"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <div v-if="user.menus[0].children">
            <el-submenu :index="item.id+''" v-for="(item) in user.menus" :key="item.id">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{item.title}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item :index="i.url" v-for="i in item.children" :key="i.id">{{i.title}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </div>
          <div v-else>
            <el-menu-item-group>
              <el-menu-item :index="i.url" v-for="i in user.menus" :key="i.id">{{i.title}}</el-menu-item>
            </el-menu-item-group>
          </div>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <h2 class="fl">用户名：{{user.username}}</h2>
          <el-button type="primary" @click="tui" class="fr">退出</el-button>
        </el-header>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{$route.meta.title}}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { reqmenulist } from "../../request/api";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      arr: []
    };
  },
  props: [],
  computed: {
    ...mapGetters({
      user: "user"
    })
  },
  methods: {
    ...mapActions({ changeUser: "changeUser" }),
    tui() {
      this.changeUser({});
      this.$router.push("/login");
    }
  },
  mounted() {
    reqmenulist({ istree: true }).then(res => {
      this.arr = res.data.list;
    });
  }
};
</script>
<style lang="less" scoped>
.box {
  .el-aside {
    background-color: #003333;
    height: 100vh;
  }
  .el-header {
    background-color: #cccccc;
  }
  .el-breadcrumb {
    padding: 20px 0;
  }
  .fl {
    line-height: 60px;
  }
}
</style>